package com.dgut.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import com.dgut.common.SelectRole;
import com.dgut.pojo.Contract;
import com.dgut.service.ContractService;
import com.dgut.utils.PageRequestInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.concurrent.ConcurrentHashMap;

@CrossOrigin
@Api("ContractController")
@RestController
@RequestMapping("/contract")
public class ContractController {
    @Resource
    private ContractService contractService;
    /**
     * start-zwb
     */
    @ApiOperation(value = "获取合同表")
    @PostMapping("/getContractList")
    public Object getContractList(@ApiParam(value = "分页信息",required = true) @RequestBody PageRequestInfo pageRequestInfo) {
        ConcurrentHashMap map = new ConcurrentHashMap();
        map.put("contractList",contractService.getContractList(pageRequestInfo));
        return map;
    }
    @ApiOperation(value = "获取已上架的合同表")
    @PostMapping("/getContractListOnShelves")
    public Object getContractListOnShelves(@ApiParam(value = "分页信息",required = true) @RequestBody PageRequestInfo pageRequestInfo,
                                           @ApiParam(value="合同类型",required = false) @RequestParam(required = false) String type) {
        ConcurrentHashMap map = new ConcurrentHashMap();
        map.put("contractList",contractService.getContractListOnShelves(pageRequestInfo,type));
        return map;
    }
    @ApiOperation(value = "通过合同名获取合同表")
    @PostMapping("/getContractByName")
    public Object getContractListByName(@ApiParam(value = "合同类型",required = true) @RequestParam String name) {
        ConcurrentHashMap map = new ConcurrentHashMap();
        map.put("contractList",contractService.getContractByName(name));
        return map;
    }
    @ApiOperation(value = "通过合同类型获取合同表")
    @PostMapping("/getContractListByType")
    public Object getContractListByType(@ApiParam(value = "合同类型",required = true) @RequestParam String type) {
        ConcurrentHashMap map = new ConcurrentHashMap();
        map.put("contractList",contractService.getContractByType(type));
        return map;
    }

    @SaCheckLogin
    @SaCheckRole(SelectRole.ADMIN)
    @ApiOperation(value = "新增合同信息")
    @PostMapping("/addContract")
    public Object addContract(@ApiParam(value = "新增合同信息",required = true) @RequestBody Contract contract) {
        return contractService.addContract(contract);
    }
    @SaCheckLogin
    @SaCheckRole(SelectRole.ADMIN)
    @ApiOperation(value = "修改合同信息")
    @PostMapping("/modifyContract")
    public Object modifyContract(@ApiParam(value = "修改合同信息",required = true) @RequestBody Contract contract) {
        return contractService.modifyContract(contract);
    }
    @SaCheckLogin
    @SaCheckRole(SelectRole.ADMIN)
    @ApiOperation(value = "删除合同信息")
    @PostMapping("/deleteContract")
    public Object deleteContract(@ApiParam(value = "合同id",required = true) @RequestParam Integer id) {
        return contractService.deleteContract(id);
    }
    @SaCheckLogin
    @SaCheckRole(SelectRole.ADMIN)
    @ApiOperation(value = "合同上架")
    @PostMapping("/putOnContract")
    public Object putOnContract(@ApiParam(value = "合同id",required = true) @RequestParam Integer id) {
        return contractService.putOnContract(id);
    }
    @SaCheckLogin
    @SaCheckRole(SelectRole.ADMIN)
    @ApiOperation(value = "合同下架")
    @PostMapping("/takeDownContract")
    public Object takeDownContract(@ApiParam(value = "合同id",required = true) @RequestParam Integer id) {
        return contractService.takeDownContract(id);
    }

    /**
     *
     * end-zwb
     */


    /**
     * start-gxd
     */
    /**
     * end-gxd
     */


    /**
     * start-lzh
     */
    /**
     * end-lzh
     */

    /**
     * start-hwf
     */
    /**
     * end-hwf
     */

    /**
     * start-hqq
     */
    @ApiOperation(value = "通过合同名称获取合同表")
    @PostMapping("/getContractListOnShelvesByName")
    public Object getContractListOnShelvesByName(@ApiParam(value = "分页信息",required = true)PageRequestInfo pageRequestInfo,
                                                 @ApiParam(value = "合同名称",required = true) @RequestParam String name) {
        return contractService.getContractListOnShelvesByName(pageRequestInfo,name);
    }
    /**
     * end-hqq
     */
}